#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int sgn(int x){return x<0?-1:1;}
inline int pd(int x,int y){return !x||!y?1:(sgn(x)==sgn(y));}
main(){
  freopen("game.in","r",stdin);
  freopen("game.out","w",stdout);
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int t; cin>>t;
  while(t--){
    int n,c1=0,c2=0; cin>>n;
    vector<int> a(n),b(n);
    for(auto &i:a)cin>>i;
    for(auto &i:b)cin>>i;
    bool f=true;
    for(int i=0;i<n&&f;i++)
      if(!a[i]&&b[i])f=false;
    if(!f){cout<<"-1\n"; continue;}
    if(n==1){cout<<abs(a[0]-b[0])<<'\n'; continue;}
    if(n==2){
      vector<int> d(n);
      for(int i=0;i<n;i++)
        d[i]=b[i]-a[i];
      if(!pd(d[0],d[1]))cout<<abs(d[0])+abs(d[1])<<'\n';
      else cout<<max(abs(d[0]),abs(d[1]))<<'\n';
      continue;
    }
    if(*min_element(b.begin(),b.end())){
      adjacent_difference(a.begin(),a.end(),a.begin());
      adjacent_difference(b.begin(),b.end(),b.begin());
      for(int i=0;i<n;i++){
        if((a[i]-=b[i])>=0)c1+=a[i];
        else c2-=a[i];
      }
      cout<<min(c1,c2)+abs(c1-c2)<<'\n'; continue;
    }
    if(n<=3){
      vector<int> d(n);
      for(int i=0;i<n;i++)
        d[i]=b[i]-a[i];
      if(!pd(d[0],d[1])&&!pd(d[1],d[2])){
        if(!b[1]&&d[0]>=0&&d[2]>=0)cout<<abs(d[1])+max(abs(d[0]),abs(d[2]))<<'\n';
        else cout<<abs(d[0])+abs(d[1])+abs(d[2])<<'\n';
      }
      else if(pd(d[0],d[1])&&pd(d[1],d[2])&&pd(d[0],d[2])&&abs(d[1])<min(abs(d[0]),abs(d[2]))){
        if(!d[0]||!d[2])cout<<max({abs(d[0]),abs(d[1]),abs(d[2])})<<'\n';
        else if(b[1])cout<<abs(d[1])+abs(d[2]-d[1])+abs(d[0]-d[1])<<'\n';
        else cout<<max({abs(d[0]),abs(d[1]),abs(d[2])})<<'\n';
      }
      else{
        int c1=0,c2=0;
        for(int i:d)
          if(i<0)c1=min(c1,i);
          else c2=max(c2,i);
        cout<<c2-c1<<'\n';
      }
      continue;
    }
    cout<<"0\n";
  }
  return 0;
}